import { http } from '@/utils/request'
import type { ListSysDictionaryType, SysDictionaryDataType, SysDictionaryType } from './model'

/**
 * 获取字典列表
 * @param params
 */
export const getDictListAPI = (params?: ListSysDictionaryType) => {
  return http.request<PageResult<SysDictionaryType>>('get', '/sys_dictionary', { params })
}

/**
 * 新增字典
 * @param data
 */
export const addDictAPI = (data: SysDictionaryType) => {
  return http.request<number>('post', '/sys_dictionary', { data })
}

/**
 * 更新字典
 * @param id
 * @param data
 */
export const updateDictAPI = (id: number, data: SysDictionaryType) => {
  return http.request<void>('put', `/sys_dictionary/${id}`, { data })
}

/**
 * 删除字典
 * @param id
 */
export const deleteDictAPI = (id: number) => {
  return http.request<void>('delete', `/sys_dictionary/${id}`)
}

/**
 * 获取字典数据内容列表
 * @param type 字典类型
 */
export const getDictDataListAPI = (type: string) => {
  return http.request<SysDictionaryDataType[]>('get', `/sys_dictionary/data/${type}`)
}

/**
 * 新增字典数据
 * @param data
 */
export const addDictDataAPI = (data: SysDictionaryDataType) => {
  return http.request<number>('post', '/sys_dictionary/data', { data })
}
/**
 * 更新字典数据
 * @param id 字典数据ID
 * @param data
 */
export const updateDictDataAPI = (id: number, data: SysDictionaryDataType) => {
  return http.request<void>('put', `/sys_dictionary/data/${id}`, { data })
}
/**
 * 删除字典数据
 * @param id
 */
export const deleteDictDataAPI = (id: number) => {
  return http.request<void>('delete', `/sys_dictionary/data/${id}`)
}
